Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow use in same-origin children, add Feature Policy integration #13

Merged
merged 11 commits into from
Sep 24, 2019

Conversation

anssiko
Copy link
Member

@anssiko anssiko commented Aug 31, 2017

Per @clelland's suggestion in #10 (comment) this change allows Battery Status API use in same-origin children, and adds Feature Policy integration.

PTAL @clelland @RByers @mounirlamouri @riju

Fixes #10.


Preview | Diff

@anssiko
Copy link
Member Author

anssiko commented Sep 19, 2017

@clelland @RByers @mounirlamouri, any concerns?

If I don't hear any, I'll merge this and @riju will update the Chrome's implementation accordingly.

@RByers
Copy link

RByers commented Sep 19, 2017

Looks reasonable to me. Is the plan to add a feature control hook later?

@clelland
Copy link

clelland commented Sep 19, 2017

The only forwards-incompatibility I can see with Feature Policy here is that if a deeply nested frame happens to be same-origin with the top-document, then it will be granted access to the API by default, while feature policy would disallow that.

That is, in an A->B->A embedding scenario, both the top-level and the innermost frame would be able to use the battery API. With feature policy, the inner frame wouldn't be allowed to use it, unless the top-level doc granted it to the middle frame, which then further granted it to the inner one.

(That is, feature policy would allow access to same-origin children -- and their same-origin children, and so on -- but not to arbitrary same-origin descendent frames)

@mounirlamouri
Copy link
Member

Do we have any idea of how common it is to have x-origin iframe usage of the Battery API? Said otherwise, are we sure we are not breaking a real use case? Are we sure this change is even web compatible?

@anssiko
Copy link
Member Author

anssiko commented Sep 20, 2017

Thanks for your comments!

Is the plan to add a feature control hook later?

@RByers, that was my initial plan. That said, we could consider adding the hook on the same pass, there's just one procedural issue that need to be cleared:

The Feature Policy spec is currently in incubation, and having an unstable normative reference might be an issue if we want to advance the Battery Status API to Candidate Recommendation and beyond.

@dontcallmedom to confirm whether we could make an exception here.

Do we have any idea of how common it is to have x-origin iframe usage of the Battery API?

@mounirlamouri, I'd like to know as well, but I don't have any data.

If we care strongly about this, would Chrome be fine with us adding telemetry to figure out how common x-origin iframe usage is?

A->B->A embedding scenario

@clelland, I'd expect many other platform features be similarly impacted? If so, I wouldn't be concerned about this case at hand specifically.

Couple of questions to @clelland et al.:

Feature Policy "v1" shipped in Chrome M62. Does it have all the features implemented we'd need for this spec to integrate with it?

Do you have established conventions for spec authors on how to hook into the Feature Policy spec the right way. I'm looking for normative spec language I could borrow similarly to e.g. https://w3c.github.io/webappsec-secure-contexts/#new This helps keep specs consistent.

Thanks!

@dontcallmedom
Copy link
Member

re CR transition with a reference to an unstable spec - this won't block transition to CR (although we would want to highlight it in the transition request), but may block transition to PR. That being said, transition to PR needs a 2nd implementation we don't have yet.

@anssiko
Copy link
Member Author

anssiko commented Sep 20, 2017

Thanks for the confirmation @dontcallmedom.

With that, I'd be happy to hook this spec into the Feature Policy spec when shown the preferred conventions in doing so.

@clelland
Copy link

@anssiko -- I think that we do have all of the features implemented in Chromium to do that. As long as the plan is just to reject the promise when disallowed, then it should be pretty simple.

I've written up a spec integration guide at https://github.com/WICG/feature-policy/blob/gh-pages/integration.md -- it's not strictly normative, but take a look and see if gives you enough guidance for the wording. If there's anything that I can add to that to help you out, I'm glad to do it.

@anssiko
Copy link
Member Author

anssiko commented Sep 21, 2017

@clelland, thanks, the integration guide is very helpful.

I added Feature Policy integration in c2083ad, PTAL. See also the preview.

(I assumed the integration guide means "SecurityError" DOMException.)

@clelland
Copy link

@anssiko: Yes, that should totally read SecurityError DOMException, thanks :) PR fired. The actual error, though, should be whatever makes sense for the API -- whether rejecting a promise, or returning an error code, the important thing is just defining some way for the API to fail when disabled.

This change LGTM, though -- thanks!

@anssiko
Copy link
Member Author

anssiko commented Sep 22, 2017

@mounirlamouri PTAL and merge this PR if you're happy.

@anssiko
Copy link
Member Author

anssiko commented Oct 2, 2017

@mounirlamouri, gentle ping.

Others on this PR seem to be fine with this change, would like to get your explicit OK prior to merging.

@anssiko anssiko changed the title Allow use in same-origin children Allow use in same-origin children, add Feature Policy integration Oct 9, 2017
@anssiko
Copy link
Member Author

anssiko commented Oct 18, 2017

@mounirlamouri, we'll merge this PR unless we hear concerns from you by next Tuesday 24 Oct, to be followed by a corresponding patch to Chromium.

@anssiko
Copy link
Member Author

anssiko commented Oct 23, 2017

@Honry, as we prepare for this PR to land, could you evaluate the gaps in the battery-status test suite (in the spirit of test as you commit, soon to be adopted for all deliverables), and update the test suite accordingly? Even if I see my name in OWNERS, I may not have the cycles to pull off the test suite update at this time, and I'd +1 you to become an owner for the battery status test suite.

On a quick glimpse, I think we need to update the iframe tests and add new tests the Feature Policy integration, and test interesting edge cases such as #13 (comment)

@foolip, this is another API that needs a bunch of manual tests due to its inherent nature, similarly to Vibration API. Is the following guide still considered the state of the art in manual w-p-t testing? :-)

http://web-platform-tests.org/writing-tests/manual.html

@Honry
Copy link
Contributor

Honry commented Oct 23, 2017

@anssiko, according to the test as you commit policy, would you please add a label "needs tests" to this PR?

I will add a corresponding PR in w-p-t to reflect the changes and involve my name in OWNERS file.
Then revisit current test coverage. :)

@anssiko
Copy link
Member Author

anssiko commented Oct 23, 2017

would you please add a label "needs tests" to this PR?

Done. Thanks for your help updating this test suite too!

Honry added a commit to Honry/web-platform-tests that referenced this pull request Oct 23, 2017
 - Add feature-policy tests
 - Disallow using battery in cross-origin iframe
 - Allow using battery in same-origin iframe
 w3c/battery#13
@Honry
Copy link
Contributor

Honry commented Oct 23, 2017

I will add a corresponding PR in w-p-t to reflect the changes and involve my name in OWNERS file.

Done at web-platform-tests/wpt#7944, PTAL.

@mounirlamouri
Copy link
Member

Sorry for the delay Anssi :( I still disagree with this change as I think it's curing thy symptoms, not the disease. The API should have an implementation that is privacy friendly.

This said, in practice, my main concern is whether this will break web pages. Was a use counter added into Chrome to discover how large the impact of this change would be and whether the deprecation is web-compatible? I don't think we can disable this in Chrome without this information.

@clelland
Copy link

@mounirlamouri, I don't think we've added a use counter for that into Chrome.

When we were looking at a similar behaviour change for the Fullscreen API, I think we added one that fired every time a same-origin page was blocked from entering fullscreen.

We could add a similar counter here for battery-status, as well as one that fires when a same-origin-as-root-but-embedded-cross-origin page successfully uses the API. If we do it quickly enough, we should be be able to get that change merged for M63, to get some actual data before the end of the year.

@mounirlamouri
Copy link
Member

I think something that checks the usage in x-origin iframe and another for same origin should be enough.

@clelland
Copy link

So Chrome doesn't currently restrict getBattery at all. Fully complying with this change would block the API in Chrome:

  • in all insecure contexts
  • in any frame which is at a different origin than its parent (without an appropriate feature policy)
  • in any frame which is at a different origin than the top-level document (again, without an appropriate feature policy)

If we add counters for those situations, then we should have a good idea how much usage would be broken by adopting this change (and also adopting the current spec as-is).

(Also, this is Chrome-specific, but both caniuse and the API confluence dashboard suggest that the API is not implemented anywhere else -- if that's wrong, it could change the 'web-compatible' calculation quite a bit)

@anssiko
Copy link
Member Author

anssiko commented Sep 18, 2018

(Here's an HTML diff comparing this branch with gh-pages to ease review, e.g. at F2F. I enabled pr-preview to automate this for any subsequent PRs.)

promise</a> with a "<a>SecurityError</a>" <a>DOMException</a>, return
this <a>Navigator</a> object's <a>battery promise</a> and abort these
steps.
<li>If this <a>Navigator</a> object's <a>relevant global object</a>'s

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With feature policy integration, I think you can replace this entire paragraph with something like

If this Navigator object's relevant global object's associated Document is not allowed to use the battery feature, then reject...

Because the default allowlist is 'self', that will automatically take care of the same-origin embed case, while allowing cross-origin usage only if explicitly enabled by the embedding document (which this paragraph still prohibits, I think)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I pushed an update in an attempt to make use of "allowed to use". Please take a look. (I'm happy to see "allowed to use" abstracted out and reusable.)

index.html Outdated
The Battery Status API is a <a>policy-controlled feature</a>, as
defined by Feature Policy [[!FEATURE-POLICY]]. The <a>feature name</a>
for the Battery Status API is "<code>battery</code>". The <a>default
allowlist</a> for the Battery Status API is <code>« "self" »</code>.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nit: the value for the default allowlist would be 'self', with single quotes included

You can just say now

The Battery Status API is a policy-controlled-feature identified by the string "battery". It's default allowlist is 'self'.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto, pushed an update per your proposal.

- Use 'allowed to use' as a condition for rejection, move the old
  text to a note
- Align Feature Policy integration section with the latest prose
- Fix allowlist notation
Copy link

@clelland clelland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small comment about the non-normative explanation; this looks great otherwise.

index.html Outdated
<code>Document</code></a>'s <a>browsing context</a>'s <a>active
document</a>'s <a>origin</a> is not <a>same origin-domain</a> with
the <a>origin</a> of the <a>current settings object</a> of this
<a>Navigator</a> object.
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could add something like "unless specifically allowed by the document's feature policy." to this, if you wanted to be clear that it's possible to grant access to cross-origin subframes, but you have to be deliberate about it. The default situation is exactly as you describe here.

Note it is possible to explicitly grant access to cross-origin
subframes using feature policy, in which case the promise is
not rejected.
@anssiko
Copy link
Member Author

anssiko commented Oct 3, 2018

@clelland, thanks for your comments! I integrated your suggestion and pushed an update. At F2F, we can gauge whether we have consensus to land this and update the implementation(s) accordingly. I invited @mounirlamouri to join as well.

</h2>
<p data-link-for="Navigator">
The Battery Status API is a <a>policy-controlled feature</a> identified
by the string "<code>battery</code>". It's default allowlist is
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Note to self: s/It’s/Its/)

@anssiko
Copy link
Member Author

anssiko commented Oct 22, 2018

@anssiko
Copy link
Member Author

anssiko commented Jun 26, 2019

(Rebased with gh-pages and fixed merge conflicts in a9e3c94.)

@anssiko
Copy link
Member Author

anssiko commented Aug 16, 2019

Time for the annual update to this issue ☺️

There are the following battery use counters invoked in getBattery.

In percentages of Chrome page loads (across all channels and platforms) that use the corresponding feature at least once, as of today:

@css-meeting-bot
Copy link
Member

The Devices and Sensors Working Group just discussed Battery Status, and agreed to the following:

  • RESOLUTION: Replace SecurityError with NotAllowedError in step 2 of getBattery() algorithm and merge #13.
The full IRC log of that discussion <reillyg> Topic: Battery Status
<anssik> github: https://github.com//pull/13
<reillyg> Anssi: In Chrome the battery status API is currently available in cross-origin iframes.
<reillyg> ... Mozilla had concerns about this API and dropped it a long time ago.
<reillyg> Tom: Looking at stats on HTTP Archive ads are the biggest user of this cross-origin.
<reillyg> Reilly: It doesn't seem like we've seen a clearly articulated reason not to land this PR.
<tomayac> Usage stats: https://chromestatus.com/metrics/feature/timeline/popularity/2198
<reillyg> Anssi: The issue is breaking sites.
<reillyg> flaki: If you have metrics for APIs like this then from a standardization point of view we should provide more restrictive versions of these APIs.
<reillyg> ... For example, "is on battery power" vs. "what is the current battery level"
<reillyg> Anssi: In retrospect, agreed.
<reillyg> ... The current usage is very high for taking this API away for cross-origin contexts.
<reillyg> Reilly: Ian, do we have exerience taking away APIs like this with FP in other contexts?
<reillyg> ... What has been the reaction?
<reillyg> Ian: Geolocation is currently under feature policy.
<reillyg> Tom: We didn't hear massive outcry.
<reillyg> Ian: It's easy to fix in legitimate use cases.
<reillyg> Anssi: Do we know what will break?
<reillyg> Reilly: chromestatus.com includes top URLs using the API.
<tomayac> The post from geolocation days: https://developers.google.com/web/updates/2016/04/geolocation-on-secure-contexts-only
<reillyg> Reilly: We should post an Intent to Implement/Deprecate and just do it.
<reillyg> Ian: Some people think we should just cut it down to a small number of buckets.
<reillyg> Reilly: I think we should do both.
<tomayac> Intent to deprecate: insecure usage of powerful features: https://groups.google.com/a/chromium.org/forum/#!msg/blink-dev/2LXKVWYkOus/gT-ZamfwAKsJ
<reillyg> Ian: Is the proposal still to never resolve the promise?
<reillyg> Reilly: Why not reject with NotAllowedError?
<reillyg> Anssi: For compatibility with existing content.
<reillyg> Reilly: Shouldn't script have already been written to handle other failures?
<reillyg> Ian: We could browse the web with canary running with this disabled and see how bad it is.
<reillyg> Reilly: Both mechanisms will break content but never resolving will break content in weirder ways.
<tomayac> and wronger ways
<reillyg> Reilly: The current PR text rejects with a SecurityError. It should be a NotAllowedError but otherwise is the right behavior.
<reillyg> PROPOSED RESOLUTION: Replace SecurityError with NotAllowedError and merge existing PR.
<reillyg> PROPOSED RESOLUTION: Replace SecurityError with NotAllowedError and merge #13.
<reillyg> PROPOSED RESOLUTION: Replace SecurityError with NotAllowedError in step 2 of getBattery() algorithm and merge #13.
<reillyg> Anssi: Any concerns given wide-scale implications?
<reillyg> [None heard]
<reillyg> Ian: Are there other interfaces in the Battery API which should be gated by FP?
<reillyg> Anssi: getBattery() is the only entrypoint.
<reillyg> RESOLUTION: Replace SecurityError with NotAllowedError in step 2 of getBattery() algorithm and merge #13.

Error message:
Couldn't match "EventTarget" to anything in the document or in any
other document cited in this specification: webidl
@anssiko
Copy link
Member Author

anssiko commented Sep 24, 2019

Merging this PR per F2F resolution #13 (comment). This branch includes 3e08915 that was part of the resolution.

@anssiko anssiko merged commit 5a628d9 into gh-pages Sep 24, 2019
Honry added a commit to Honry/web-platform-tests that referenced this pull request Sep 25, 2019
 - Add feature-policy tests
 - Disallow using battery in cross-origin iframe
 - Allow using battery in same-origin iframe
 w3c/battery#13
Honry added a commit to web-platform-tests/wpt that referenced this pull request Sep 25, 2019
* Add feature-policy to battery-status

 - Add feature-policy tests
 - Disallow using battery in cross-origin iframe
 - Allow using battery in same-origin iframe
 w3c/battery#13

* Replace SecurityError with NotAllowedError

and use modern ES6
@anssiko
Copy link
Member Author

anssiko commented Sep 25, 2019

Thanks to @Honry, now also Feature Policy section is updated. Consider #24 to be a part of this PR.

moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this pull request Sep 30, 2019
…estonly

Automatic update from web-platform-tests
Add feature-policy to battery-status (#7944)

* Add feature-policy to battery-status

 - Add feature-policy tests
 - Disallow using battery in cross-origin iframe
 - Allow using battery in same-origin iframe
 w3c/battery#13

* Replace SecurityError with NotAllowedError

and use modern ES6

--

wpt-commits: fab60f68f7227113a171fb8e17d84d2f5983109b
wpt-pr: 7944
xeonchen pushed a commit to xeonchen/gecko that referenced this pull request Sep 30, 2019
…estonly

Automatic update from web-platform-tests
Add feature-policy to battery-status (#7944)

* Add feature-policy to battery-status

 - Add feature-policy tests
 - Disallow using battery in cross-origin iframe
 - Allow using battery in same-origin iframe
 w3c/battery#13

* Replace SecurityError with NotAllowedError

and use modern ES6

--

wpt-commits: fab60f68f7227113a171fb8e17d84d2f5983109b
wpt-pr: 7944
gecko-dev-updater pushed a commit to marco-c/gecko-dev-comments-removed that referenced this pull request Oct 4, 2019
…estonly

Automatic update from web-platform-tests
Add feature-policy to battery-status (#7944)

* Add feature-policy to battery-status

 - Add feature-policy tests
 - Disallow using battery in cross-origin iframe
 - Allow using battery in same-origin iframe
 w3c/battery#13

* Replace SecurityError with NotAllowedError

and use modern ES6

--

wpt-commits: fab60f68f7227113a171fb8e17d84d2f5983109b
wpt-pr: 7944

UltraBlame original commit: f722b65ec0ba6824338b4d3e9d5a62e2a28011ad
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified-and-comments-removed that referenced this pull request Oct 4, 2019
…estonly

Automatic update from web-platform-tests
Add feature-policy to battery-status (#7944)

* Add feature-policy to battery-status

 - Add feature-policy tests
 - Disallow using battery in cross-origin iframe
 - Allow using battery in same-origin iframe
 w3c/battery#13

* Replace SecurityError with NotAllowedError

and use modern ES6

--

wpt-commits: fab60f68f7227113a171fb8e17d84d2f5983109b
wpt-pr: 7944

UltraBlame original commit: f722b65ec0ba6824338b4d3e9d5a62e2a28011ad
gecko-dev-updater pushed a commit to marco-c/gecko-dev-wordified that referenced this pull request Oct 5, 2019
…estonly

Automatic update from web-platform-tests
Add feature-policy to battery-status (#7944)

* Add feature-policy to battery-status

 - Add feature-policy tests
 - Disallow using battery in cross-origin iframe
 - Allow using battery in same-origin iframe
 w3c/battery#13

* Replace SecurityError with NotAllowedError

and use modern ES6

--

wpt-commits: fab60f68f7227113a171fb8e17d84d2f5983109b
wpt-pr: 7944

UltraBlame original commit: f722b65ec0ba6824338b4d3e9d5a62e2a28011ad
@anssiko
Copy link
Member Author

anssiko commented Oct 16, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow use from within secure context and top-level browsing context only
9 participants